
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <fcntl.h>
#include <unistd.h>

#include <errno.h>

#include <libqserver.h>

int main(int argc, char **argv)
{
	int oc = 0;

	char ifname[32] = {0};
	unsigned short port = 0;

	Lib_QServer *qserver = NULL;

	if(1 == argc)
	{
		printf("-i\tinterface\n-p port\n");
	}

	while(0 < (oc = getopt(argc, argv, "i:p:")))
	{
		switch(oc)
		{
			case 'i':
				strncpy(ifname, optarg, sizeof(ifname));
				break;
			case 'p':
				port = (unsigned short)strtoul(optarg, NULL, 0);
				break;
			case '?':
				goto out;
				break;
			case ':':
				goto out;
				break;
		}
	}

	if(0 >= strlen(ifname) || 0 >= port)
	{
		goto out;
	}

	printf("ip: %s:%d\n", ifname, port);

	qserver = Lib_QServer::getObject(ifname, port);

	if(NULL == qserver)
	{
		goto out;
	}

	qserver->loop();

	if(NULL != qserver)
	{
		delete qserver;
		qserver = NULL;
	}

out:
	return 0;
}
